package org.exhaust.framework.net.cmpp20.protocol.server;

import io.netty.buffer.ByteBuf;
import lombok.Data;
import org.exhaust.framework.net.cmpp20.protocol.AbstractCMPPBodyServer;
import org.exhaust.framework.net.common.protocol.FrameHeader;

@Data
public class CMPPSubmitResp extends AbstractCMPPBodyServer {

    private long msgId;
    /**
     * 结果
     * 0：正确
     * 1：消息结构错
     * 2：命令字错
     * 3：消息序号重复
     * 4：消息长度错
     * 5：资费代码错
     * 6：超过最大信息长
     * 7：业务代码错
     * 8：流量控制错
     * 9~ ：其他错误
     */
    private int result;
    @Override
    protected long getCommandType() {
        return 0x80000004;
    }

    @Override
    public void decode(ByteBuf in, FrameHeader header) {

    }

    public String getMMDDHHMMSS(){
        StringBuilder sb = new StringBuilder(10);
        int month = (int)((msgId >> 60) & 0x0f);
        int date = (int)((msgId >> 54) & 0x0f);
        int hh = (int)((msgId >> 50) & 0x0f);
        int mm = (int)((msgId >> 44) & 0x3f);
        int ss = (int)((msgId >> 38) & 0x3f) ;
        return sb.append(patchZero(month)).append(patchZero(date)).append(patchZero(hh)).append(patchZero(mm)).append(patchZero(ss)).toString();
    }

    private static String patchZero(int num){
        if(num <= 9){
            return "0"+num;
        }
        return ""+num;
    }
    public int getSpCode(){
        return (int)((msgId >> 16) & 0b1111111111111111111111);
    }

    public int getSequence(){
        return (int)(msgId & 0xFFFF);
    }
}
